<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%
	String path = request.getContextPath();
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>配置用户角色</title>
<script src="<%=path %>/js/formValidator-4.1.1.js" type="text/javascript" charset="UTF-8"></script>
<script src="<%=path %>/js/formValidatorRegex.js" type="text/javascript" charset="UTF-8"></script>
<script src="<%=path %>/js/DateTimeMask.js" type="text/javascript" charset="UTF-8"></script>
<script type="text/javascript">
	$(function(){
		initRole();
		//配置用户角色
		$('#confUserRole').click(function() {
			var bool = false;
			var para = '';
			$("input[name='checkItems'][type='checkbox']").each(function(i) {
				if ($(this).attr("checked") == 'checked') {
					para += $(this).attr('id') + ",";
					bool = true;
				}
			});
			if (confirm("确认要重新配置该用户相关角色?")) {
				window.location.href = "<%=path%>/user/confUserRole.htm?checkItems=" + para.substring(0,para.length-1)
						+ "&user.id=" + $(this).attr('val');
			}
		});
	});
	//选中该用户已拥有的角色
	function initRole(){
		var allGroupedRes = eval('(' + "${usersRole}" + ')');
		var role_id = '';
		$.each(allGroupedRes,function(i,content){
			role_id = content['ROLE_ID'];
			$('#'+role_id).attr('checked',true);
		});
	};
</script>
</head>
<body>
	<form id="rForm" action="<%=path%>/user/confUserRole.htm" method="post">
		<table style="width: 100%; border-collapse: collapse; border-color: #D4D4D4;">
			<tr>
				<td width="20%"></td>
				<td>
					<table style="width: 100%;border: outset 1pt;horizontal-align: right;">
						<tr style="background-color: #DEF2FF">
					      <td align="center" colspan="2">配置用户:${user.name }的角色</td>
					    </tr>
					    	<c:choose>
								<c:when test="${allRole == null || fn:length(allRole) <= 0}">
									<tr class="tr_nomal"><td colspan="2" style="text-align: center;">无角色</td></tr>
								</c:when>
								<c:otherwise>
									<c:forEach items="${allRole }" var="res" varStatus="status">
										<c:if test="${status.index%2 == 0}"><tr class="tr_nomal"></c:if>
											<td width="50%"><input type="checkbox" name="checkItems" id="${res['R_ID'] }"></input>&nbsp;&nbsp;${res['ROLE_NAME'] }</td>
										<c:if test="${status.index+1 == fn:length(allRole) && fn:length(allRole)%2 != 0 }">
											<td width="50%"></td>
										</c:if>
										<c:if test="${status.index%2 != 0}"></tr></c:if>
									</c:forEach>
								</c:otherwise>
						</c:choose>
						<tr>
							<td></td>
							<td style="padding-left: 100px;padding-right: 10px;"><input id="confUserRole" val="${user.id }" type="button" value="提交"></input></td>
						</tr>
					</table>
				</td>
				<td width="20%"></td>
			</tr>
		</table>
	</form>
</body>
</html>